package com.ymttest.database.sqlwapper;

import java.util.List;
import java.util.Map;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.SpuProduct;
import com.ymttest.database.model.SpuProperty;

public class SpuPropertyWapper {
	SqlManager manage;

	public SpuPropertyWapper() {
		manage = new SqlManager("intpro");
	}
	
	
	
	/**
	 * 根据规格id查询规格
	 * @param templateId
	 * @return
	 * @throws InterruptedException
	 */
	public SpuProperty selectSpuPropertById(Integer templateId) throws InterruptedException{
		SpuProperty SpuProperty=(SpuProperty) manage.getSelectResults("com.ymttest.database.mapping.SpuPropertyMapper.selectByPrimaryKey", templateId).get(0);
		manage.commit();
		return SpuProperty;
	}
	
	
	/**
	 * 根据三级类目id查询规格
	 * @param thirdcategoryid
	 * @return
	 * @throws InterruptedException
	 */
	public List<SpuProperty> selectByThirdcategoryidId(Integer thirdcategoryid) throws InterruptedException{
		List<SpuProperty> m =  (List<SpuProperty>) manage.getSelectResults("com.ymttest.database.mapping.SpuPropertyMapper.selectByThirdcategoryidId", thirdcategoryid);
		manage.commit();
		return m;
	}
	/**
	 * 查询spu商品信息
	 * @param spuid
	 * @return
	 * @throws InterruptedException
	 */
	public Map selectSpuProductInfoBySpuid(Integer spuid) throws InterruptedException{
		Map m = (Map) manage.getSelectResults("com.ymttest.database.mapping.SpuPropertyMapper.selectSpuProductInfoBySpuid", spuid).get(0);
		manage.commit();
		return m;
	}
	
	public Map selectSpuProductInfoByProductId(String ProductId) throws InterruptedException{
		Map m =  (Map) manage.getSelectResults("com.ymttest.database.mapping.SpuPropertyMapper.selectSpuProductInfoByProductId", ProductId).get(0);
		manage.commit();
		return m;
	}
	/**
	 * 查询spu规格
	 * @param spuid
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectSpuPropertyInfosBySpuid(Integer spuid) throws InterruptedException{
		List<Map> m=(List<Map>) manage.getSelectResults("com.ymttest.database.mapping.SpuPropertyMapper.selectSpuPropertyInfosBySpuid", spuid);
		manage.commit();
		return m;
	}
	/**
	 * http://productspu.iapi.ymatou.com/api/Spu/SyncPspSpuProduct
	 * @param pid
	 * @return
	 * @throws InterruptedException
	 */
	public Map selectProductInfoByProductId(String pid) throws InterruptedException{
		Map m=(Map) manage.getSelectResults("com.ymttest.database.mapping.SpuPropertyMapper.selectProductInfoByProductId", pid).get(0);
		manage.commit();
		return m;
	}
	/**
	 * http://productspu.iapi.ymatou.com/api/Spu/SyncPspSpuProduct
	 * @param pid
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectProductPropertyByProductId(String pid) throws InterruptedException{
		List<Map> m=(List<Map>) manage.getSelectResults("com.ymttest.database.mapping.SpuPropertyMapper.selectProductPropertyByProductId", pid);
		manage.commit();
		return m;
	}
	/**
	 * 查询所有数据 对比用
	 * @return
	 * @throws InterruptedException
	 */
	public List<SpuProduct> selectAllSpuProduct() throws InterruptedException{
		List<SpuProduct> list= (List<SpuProduct>) manage.getSelectResults("com.ymttest.database.mapping.SpuPropertyMapper.selectAllSpuProduct", null);
		manage.commit();
		return list;
	}
	
	
	/**
	 * http://productspu.iapi.ymatou.com/api/Spu/GetSpuPropertyList
	 * @param spuid
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectSpuPropertyBySpuId(Integer spuid) throws InterruptedException{
		List<Map> list=(List<Map>) manage.getSelectResults("com.ymttest.database.mapping.SpuPropertyMapper.selectSpuPropertyBySpuId", spuid);
		manage.commit();
		return list;
	}
	public int updateSpuStatusDeleteById(Integer spuid) throws InterruptedException{
		int i=manage.update("com.ymttest.database.mapping.SpuPropertyMapper.updateSpuStatusDeleteById", spuid);
		manage.commit();
		return i;
	}

	public int updateSpuIsPspSpu(Integer spuid) throws InterruptedException{
		int i=manage.update("com.ymttest.database.mapping.SpuPropertyMapper.updateSpuIsPspSpu", spuid);
		manage.commit();
		return i;
	}
	/**
	 * http://productspu.iapi.ymatou.com/api/Spu/GetSpuPropertyList
	 * @param spuid
	 * @return
	 * @throws InterruptedException
	 */
	public List<Map> selectSpuCategoryBySpuId(Integer spuid) throws InterruptedException{
		List<Map> list=(List<Map>) manage.getSelectResults("com.ymttest.database.mapping.SpuPropertyMapper.selectSpuCategoryBySpuId", spuid);
		manage.commit();
		return list;
	}
	public static void main(String[] args) throws Exception {
		//System.out.println(new YmtProductDescExtraWapper().selectByTemplateId(1).getPicUrls());
		System.out.println(new SpuPropertyWapper().selectSpuPropertyBySpuId(262936));
		//System.out.println(new SpuPropertyWapper().selectSpuPropertyInfosBySpuid(237330));
	
	}
}
